// pages/group/index.js
var app = getApp(),
  a = app.requirejs("core");
Page({
  data: {
    currentTab: 0,
    scrollTop: 0,
    page: 0,
    groupList: [],
    loading: true
  },
  onLoad: function(options) {
    var systemInfo = wx.getSystemInfoSync()
    this.setData({
      windowHeight: systemInfo.windowHeight
    })
    this.setCurrentData()
  },
  onShow: function() {

  },
  setCurrentData: function() {
    var t = this;
    t.setData({
        loading: true
      }),
      a.get("Pintuan/ptGroupList", {
        page: t.data.page,
        status: t.data.currentTab,
        uid: getApp().getCache("userinfo").uid
      }, function(e) {
        0 == e.code ? (t.setData({
            loading: false,
            show: true
          }),
          e.info.length > 0 && t.setData({
            page: t.data.page + 1,
            groupList: t.data.groupList.concat(e.info)
          }),
          e.info.length < 10 && t.setData({
            loaded: true
          })) : a.alert(e.msg)
      }, true)  
  },
  
  showGoodsDetail: function(e) {
    var id = e.currentTarget.dataset.id;
    if (!id) return;
    app.redirect('goods/detail', "gid=" + id)
  },
  showGroupInfo: function(e) {
    var id = e.currentTarget.dataset.id;
    console.log(id,"魏婴")
    app.redirect('group/detail', "id=" + id)
  },
  showOrderInfo: function(e) {
    var id = e.currentTarget.dataset.id;
    app.redirect('orders/detail', "oid=" + id)

  },
  // 滑动切换tab 
  bindChange: function(e) {
    this.data.page = 0
    this.data.groupData = []
    this.data.loading = true
    this.data.currentTab = e.detail.current
    this.setData({
      loading: true,
      groupList: [],
      currentTab: this.data.currentTab
    })
    this.setCurrentData()
  },
  // 点击tab切换 
  swichNav: function(e) {
    if (this.data.currentTab == e.currentTarget.dataset.current) return;
    this.data.currentTab = e.currentTarget.dataset.current
    this.setData({
      currentTab: this.data.currentTab
    })
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function() {
    this.setData({
      groupList: [],
      page: 1,
      loaded: false,
    })
    this.setCurrentData()
    wx.stopPullDownRefresh();
  },
  scrolltolower: function() {
    console.log('加载更多')
    this.data.loaded || this.setCurrentData()
  }
})